package com.lucifer.sort;

/**
 * 插入排序
 *
 * @author yuxiao05@meituan.com
 * @create 2016-07-05 下午3:14
 */

public class InsertSort {
  public static void main(String[] args){
    int[] a = new int[]{2,1,4,5,3,2,6};

    for (int i = 0, j = i; i < a.length - 1; j = ++i) {
      int ai = a[i + 1];
      while (ai < a[j]) {
        a[j + 1] = a[j];
        if(j-- == 0)
          break;
      }
      a[j + 1] = ai;
    }

    for (int i : a) {
      System.out.println(i);
    }
  }
}
